<template>
    <div id="temp">
        <div class="stuInfo">
            <div class="tit">
                <span>房屋详情</span>
                <span class="icon" @click="editHouse()"></span>
            </div>
            <el-row>
                <el-col :span="7">
                    <div>
                        <el-col :span="10">
                            <span class="left">资产编号：</span>
                        </el-col>
                        <el-col :span="14">
                            <span class="right">{{houseData.asset_num}}</span>
                        </el-col>
                    </div>
                    <div>
                        <el-col :span="10">
                            <span class="left">类型：</span>
                        </el-col>
                        <el-col :span="14">
                            <span class="right">{{houseData.type}}</span>
                        </el-col>
                    </div>
                </el-col>
                <el-col :span="7">
                    <div>
                        <el-col :span="10">
                            <span class="left">资产名称：</span>
                        </el-col>
                        <el-col :span="14">
                            <span class="right">{{houseData.asset_name}}</span>
                        </el-col>
                    </div>
                </el-col>
                <el-col :span="7">
                    <div>
                        <el-col :span="10">
                            <span class="left">资产地址：</span>
                        </el-col>
                        <el-col :span="14">
                            <span class="right">{{houseData.address}}</span>
                        </el-col>
                    </div>
                </el-col>
            </el-row>
        </div>
        <div class="record">
            <el-tabs type="border-card" @tab-click="formChange" activeName="asset">
                <el-dialog title="编辑房屋信息" :visible.sync="pop" size="tiny">
                    <el-form :model="houseAdd" :label-width="width" :rules="houseRules" ref="houseRulesName">
                        <el-form-item label="资产编号" prop="asset_num">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.asset_num" size="small" placeholder="请输入资产编号"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="资产名称" prop="asset_name">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.asset_name" size="small" placeholder="请输入产品名称"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="资产地址">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.address" size="small" placeholder="请输入资产地址"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="类型">
                            <el-col :span="span">
                                <el-select v-model="houseAdd.type" placeholder="请选择">
                                    <el-option v-for="item in type" :label="item" :value="item" :key="item"></el-option>
                                </el-select>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="pop = false">取 消</el-button>
                        <el-button type="primary" @click="changeHouse()">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog title="编辑资产信息" :visible.sync="assetPop" size="tiny">
                    <el-form :model="houseAdd" :label-width="width" :rules="houseRules" ref="houseRulesName">
                        <el-form-item label="结构">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.structure" size="small" auto-complete="off"
                                          placeholder="请输入内容"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="面积" prop="area">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.area" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="购入时间">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="houseAdd.buy_time"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="使用年限">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.age" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="原值">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.value" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="购置数量">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.quantity" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="累计折旧">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.accumulated_depreciation" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="月折旧">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.month_depreciation" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="净值">
                            <el-col :span="span">
                                <el-input v-model="houseAdd.net_value" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="assetPop = false">取 消</el-button>
                        <el-button type="primary" @click="changeHouse()">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog title="添加物业信息" :visible.sync="propertyPop" size="tiny">
                    <el-form :model="propertyAdd" :label-width="width" :rules="propertyRules" ref="propertyRulesName">
                        <el-form-item label="物业名称">
                            <el-col :span="span">
                                <el-input v-model="propertyAdd.name" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="联系人" prop="contacts">
                            <el-col :span="span">
                                <el-input v-model="propertyAdd.contacts" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="联系方式">
                            <el-col :span="span">
                                <el-input v-model="propertyAdd.contact" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="propertyPop = false">取 消</el-button>
                        <el-button type="primary" @click="change('property')">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog title="添加租借信息" :visible.sync="leasePop" size="tiny">
                    <el-form :model="leaseAdd" :label-width="width" :rules="leaseRules" ref="leaseRulesName">
                        <el-form-item label="租借人" prop="lease_name">
                            <el-col :span="span">
                                <el-input v-model="leaseAdd.lease_name" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="租借起始时间">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="leaseAdd.start_time"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="租借结束时间">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="leaseAdd.end_time"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="租金/年">
                            <el-col :span="span">
                                <el-input v-model="leaseAdd.rent" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="leasePop = false">取 消</el-button>
                        <el-button type="primary" @click="change('lease')">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog title="添加维修记录" :visible.sync="maintenancePop" size="tiny">
                    <el-form :model="maintenanceAdd" :label-width="width" :rules="maintenanceRules"
                             ref="maintenanceRulesName">
                        <el-form-item label="资产编号">
                            <el-col :span="span">
                                <el-input v-model="maintenanceAdd.asset_num" size="small"
                                          auto-complete="off" disabled="disabled"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="资产名称">
                            <el-col :span="span">
                                <el-input v-model="maintenanceAdd.asset_name" size="small"
                                          auto-complete="off"
                                          disabled="disabled"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="故障发生时间">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="maintenanceAdd.start_time"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="故障现象">
                            <el-col :span="span">
                                <el-input v-model="maintenanceAdd.phenomenon" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="维修状态">
                            <el-col :span="span">
                                <el-select v-model="maintenanceAdd.condition" placeholder="请选择">
                                    <el-option
                                            v-for="item in options"
                                            :key="item"
                                            :label="item"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="故障解除时间">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="maintenanceAdd.end_time"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="金额">
                            <el-col :span="span">
                                <el-input v-model="maintenanceAdd.money" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="负责人" prop="leading_official">
                            <el-col :span="span">
                                <el-input v-model="maintenanceAdd.leading_official" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="备注">
                            <el-col :span="span">
                                <el-input v-model="maintenanceAdd.comments" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="maintenancePop = false">取 消</el-button>
                        <el-button type="primary" @click="change('maintenance')">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog title="添加保养记录" :visible.sync="maintainPop" size="tiny">
                    <el-form :model="maintainAdd" :label-width="width" :rules="maintainRules" ref="maintainRulesName">
                        <el-form-item label="资产编号">
                            <el-col :span="span">
                                <el-input v-model="maintainAdd.asset_num" size="small"
                                          auto-complete="off" placeholder="请输入" disabled="disabled"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="资产名称">
                            <el-col :span="span">
                                <el-input v-model="maintainAdd.asset_name" size="small"
                                          auto-complete="off" placeholder="请输入" disabled="disabled"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="保养内容">
                            <el-col :span="span">
                                <el-input v-model="maintainAdd.content" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="保养日期">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="maintainAdd.date"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="金额">
                            <el-col :span="span">
                                <el-input v-model="maintainAdd.money" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="负责人" prop="leading_official">
                            <el-col :span="span">
                                <el-input v-model="maintainAdd.leading_official" size="small"
                                          auto-complete="off" placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="maintainPop = false">取 消</el-button>
                        <el-button type="primary" @click="change('maintain')">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog title="添置记录" :visible.sync="acquirePop" size="tiny">
                    <el-form :model="acquireAdd" :label-width="width" :rules="acquireRules" ref="acquireRulesName">
                        <el-form-item label="类别">
                            <el-col :span="span">
                                <el-input v-model="acquireAdd.type" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="名称" prop="name">
                            <el-col :span="span">
                                <el-input v-model="acquireAdd.name" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="添置日期">
                            <el-col :span="span">
                                <el-date-picker type="date" size="small" placeholder="选择日期"
                                                v-model="acquireAdd.date"
                                                style="width: 100%;"></el-date-picker>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="数量">
                            <el-col :span="span">
                                <el-input v-model="acquireAdd.quantity" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                        <el-form-item label="单价">
                            <el-col :span="span">
                                <el-input v-model="acquireAdd.price" size="small" auto-complete="off"
                                          placeholder="请输入"></el-input>
                            </el-col>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="acquirePop = false">取 消</el-button>
                        <el-button type="primary" @click="change('acquire')">确 定</el-button>
                    </div>
                </el-dialog>
                <el-tab-pane label="资产信息" name="asset">
                    <table class="tab-table">
                        <thead>
                        <tr>
                            <th></th>
                            <th>结构</th>
                            <th>面积</th>
                            <th>购入时间</th>
                            <th>使用年限</th>
                            <th>原值</th>
                            <th>购置数量</th>
                            <th>累计折旧</th>
                            <th>月折旧</th>
                            <th>净值</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td>
                                <span class="icon edit" @click="editAsset()"></span>
                            </td>
                            <td>{{houseData.structure}}</td>
                            <td>{{houseData.area}}</td>
                            <td>{{houseData.buy_time}}</td>
                            <td>{{houseData.age}}</td>
                            <td>{{houseData.value}}</td>
                            <td>{{houseData.quantity}}</td>
                            <td>{{houseData.accumulated_depreciation}}</td>
                            <td>{{houseData.month_depreciation}}</td>
                            <td>{{houseData.net_value}}</td>
                        </tr>
                        </tbody>
                    </table>
                </el-tab-pane>
                <el-tab-pane label="物业信息" name="property">
                    <table class="tab-table">
                        <thead>
                        <tr>
                            <th width="10%">
                                <el-button type="text" @click="openAdd('property')"><span class="icon add"></span>
                                </el-button>
                            </th>
                            <th>物业名称</th>
                            <th>联系人</th>
                            <th>联系方式</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,index) in list" :key="item.id">
                            <td>
                                <span class="icon edit" @click="edit(item.id,'property')"></span>
                                <span class="icon del" @click="Del(item.id,'property')"></span>
                            </td>
                            <td>{{item.name}}</td>
                            <td>{{item.contacts}}</td>
                            <td>{{item.contact}}</td>
                        </tr>
                        </tbody>
                    </table>
                </el-tab-pane>
                <el-tab-pane label="租借信息" name="lease">
                    <table class="tab-table">
                        <thead>
                        <tr>
                            <th width="10%">
                                <el-button type="text" @click="openAdd('lease')"><span class="icon add"></span>
                                </el-button>
                            </th>
                            <th width="10%">序号</th>
                            <th>租借人</th>
                            <th>租借起始日期</th>
                            <th>租借结束日期</th>
                            <th>租金/年</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,index) in list" :key="item.id">
                            <td>
                                <span class="icon edit" @click="edit(item.id,'lease')"></span>
                                <span class="icon del" @click="Del(item.id,'lease')"></span>
                            </td>
                            <td>{{index + 1}}</td>
                            <td>{{item.lease_name}}</td>
                            <td>{{item.start_time}}</td>
                            <td>{{item.end_time}}</td>
                            <td>{{item.rent}}</td>
                        </tr>
                        </tbody>
                    </table>
                </el-tab-pane>
                <el-tab-pane label="维修保养记录" name="maintenance">
                    <el-tabs v-model="activeName" @tab-click="handleClick">
                        <el-tab-pane label="维修记录" name="maintenance">
                            <table class="tab-table">
                                <thead>
                                <tr>
                                    <th width="10%">
                                        <el-button type="text" @click="openAdd('maintenance')"><span
                                                class="icon add"></span>
                                        </el-button>
                                    </th>
                                    <th width="5%">序号</th>
                                    <th>资产编号</th>
                                    <th>资产名称</th>
                                    <th>故障发生时间</th>
                                    <th>故障现象</th>
                                    <th>维修状态</th>
                                    <th>故障解除时间</th>
                                    <th>金额</th>
                                    <th>负责人</th>
                                    <th>备注</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="(item,index) in list" :key="item.id">
                                    <td>
                                        <span class="icon edit" @click="edit(item.id,'maintenance')"></span>
                                        <span class="icon del" @click="Del(item.id,'maintenance')"></span>
                                    </td>
                                    <td>{{index + 1}}</td>
                                    <td>{{item.asset_num}}</td>
                                    <td>{{item.asset_name}}</td>
                                    <td>{{item.start_time}}</td>
                                    <td>{{item.phenomenon}}</td>
                                    <td>{{item.condition}}</td>
                                    <td>{{item.end_time}}</td>
                                    <td>{{item.money}}</td>
                                    <td>{{item.leading_official}}</td>
                                    <td>{{item.comments}}</td>
                                </tr>
                                </tbody>
                            </table>
                        </el-tab-pane>
                        <el-tab-pane label="保养记录" name="maintain">
                            <table class="tab-table">
                                <thead>
                                <tr>
                                    <th width="10%">
                                        <el-button type="text" @click="openAdd('maintain')"><span
                                                class="icon add"></span></el-button>
                                    </th>
                                    <th width="5%">序号</th>
                                    <th>资产编号</th>
                                    <th>资产名称</th>
                                    <th>保养内容</th>
                                    <th>保养日期</th>
                                    <th>金额</th>
                                    <th>负责人</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="(item,index) in list" :key="item.id">
                                    <td>
                                        <span class="icon edit" @click="edit(item.id,'maintain')"></span>
                                        <span class="icon del" @click="Del(item.id,'maintain')"></span>
                                    </td>
                                    <td>{{index + 1}}</td>
                                    <td>{{item.asset_num}}</td>
                                    <td>{{item.asset_name}}</td>
                                    <td>{{item.content}}</td>
                                    <td>{{item.date}}</td>
                                    <td>{{item.money}}</td>
                                    <td>{{item.leading_official}}</td>
                                </tr>
                                </tbody>
                            </table>
                        </el-tab-pane>
                    </el-tabs>
                </el-tab-pane>
                <el-tab-pane label="添置记录" name="acquire">
                    <table class="tab-table">
                        <thead>
                        <tr>
                            <th width="10%">
                                <el-button type="text" @click="openAdd('acquire')"><span class="icon add"></span>
                                </el-button>
                            </th>
                            <th width="5%">序号</th>
                            <th>类别</th>
                            <th>名称</th>
                            <th>添置日期</th>
                            <th>数量</th>
                            <th>单价</th>
                            <th>金额</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,index) in list" :key="item.id">
                            <td>
                                <span class="icon edit" @click="edit(item.id,'acquire')"></span>
                                <span class="icon del" @click="Del(item.id,'acquire')"></span>
                            </td>
                            <td>{{index + 1}}</td>
                            <td>{{item.type}}</td>
                            <td>{{item.name}}</td>
                            <td>{{item.date}}</td>
                            <td>{{item.quantity}}</td>
                            <td>{{item.price}}</td>
                            <td>{{item.quantity * item.price}}</td>
                        </tr>
                        </tbody>
                    </table>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
</template>

<script>
    import '../../../assets/css/info.css'

    const house = {
        asset_num: '',
        asset_name: '',
        address: '',
        type: '',
        structure: '',
        area: '',
        buy_time: '',
        age: '',
        value: '',
        quantity: '',
        accumulated_depreciation: '',
        month_depreciation: '',
        net_value: ''
    };
    const property = {
        name: '',
        contacts: '',
        contact: ''
    };
    const maintenance = {
        start_time: '',
        phenomenon: '',
        condition: '',
        end_time: '',
        money: '',
        asset_num: '',
        asset_name: '',
        comments: '',
        leading_official: '',
    };
    const maintain = {
        asset_num: '',
        asset_name: '',
        content: '',
        date: '',
        money: '',
        leading_official: '',
    };
    const lease = {
        lease_name: '',
        start_time: '',
        end_time: '',
        rent: ''
    };
    const acquire = {
        type: '',
        name: '',
        date: '',
        quantity: '',
        price: '',
    };
    export default {
        data() {
            return {
                tabLabel: '资产信息',
                id: '',
                width: '200px',
                span: 15,
                type: ["自购", "出租", "借出", "租用"],
                activeName: 'maintenance',
                list: {},
                options: ['代办', '完成'],

                pop: false,
                assetPop: false,
                houseData: {},
                houseAdd: _g.cloneJson(house),
                houseRules: {
                    asset_name: [{required: true, message: "请填写资产名称", trigger: "blur"}],
                    asset_num: [{required: true, message: "请填写资产编号", trigger: "blur"}],
                    area: [{required: true, message: "请填写资产编号", trigger: "blur"}]
                },

                propertyPop: false,
                propertyAdd: _g.cloneJson(property),
                propertyRules: {
                    contacts: [{required: true, message: "请填写联系人", trigger: "blur"}]
                },

                leasePop: false,
                leaseAdd: _g.cloneJson(lease),
                leaseRules: {
                    lease_name: [{required: true, message: "请填写租借人", trigger: "blur"}]
                },

                maintenancePop: false,
                maintenanceAdd: _g.cloneJson(maintenance),
                maintenanceRules: {
                    leading_official: [{required: true, message: "请填写负责人", trigger: "blur"}]
                },

                maintainPop: false,
                maintainAdd: _g.cloneJson(maintain),
                maintainRules: {
                    leading_official: [{required: true, message: "请填写负责人", trigger: "blur"}]
                },

                acquirePop: false,
                acquireAdd: _g.cloneJson(acquire),
                acquireRules: {
                    name: [{required: true, message: "请填写名称", trigger: "blur"}]
                },
            }
        },

        created() {
            this.id = this.$route.params.id;
            this.getHouse();
        },

        methods: {
            formChange(item) {
                this.tabLabel = item.label;
                if (item.name === 'maintenance') {
                    this.activeName = 'maintenance';
                }
                if (item.name !== 'asset') {
                    this.getList(item.name);
                }
            },

            handleClick(tab, event) {
                this.activeName = tab.name;
                this.getList(tab.name);
            },

            /* 获取数据 */
            getHouse() {
                let data = {id: this.id};
                this.apiPost('Operation/houseDetail', data).then(res => {
                    this.houseData = res
                })
            },
            getList(action) {
                let data = {pid: this.id};
                this.apiPost("Operation/house" + action + 'List', data).then(res => {
                    this.list = res;
                });
            },


            /* 打开编辑窗口 */
            editHouse() {
                let data = {id: this.id};
                this.apiPost('Operation/houseDetail', data).then(res => {
                    setTimeout(() => {
                        this.pop = true;
                        setTimeout(() => {
                            this.$refs.houseRulesName.resetFields();
                            this.houseAdd = res;
                        }, 0);
                    }, 0);
                });
            },
            editAsset() {
                let data = {id: this.id};
                this.apiPost('Operation/houseDetail', data).then(res => {
                    setTimeout(() => {
                        this.assetPop = true;
                        setTimeout(() => {
                            this.$refs.houseRulesName.resetFields();
                            this.houseAdd = res;
                        }, 0);
                    }, 0);
                });
            },
            edit(id, action) {
                let data = {id: id};
                this.apiPost('Operation/house' + action + 'Detail', data).then(res => {
                    setTimeout(() => {
                        this[action + 'Pop'] = true;
                        setTimeout(() => {
                            this.$refs[action + 'RulesName'].resetFields();
                            this[action + 'Add'] = res;
                        }, 0);
                    }, 0);
                })
            },

            /* 提交数据 */
            changeHouse() {
                this.$refs.houseRulesName.validate(valid => {
                    if (valid) {
                        this.pop = false;
                        this.assetPop = false;
                        let data = this.houseAdd;
                        this.apiPost("Operation/houseEdit", data).then(res => {
                            let remind = res.error ? "error" : "success";
                            _g.toastMsg(remind, res.msg);
                            if (!res.error) {
                                this.getHouse();
                            } else {
                                this.pop = true;
                            }
                        });
                    } else {
                        return false;
                    }
                });
            },
            change(action) {
                this.$refs[action + 'RulesName'].validate(valid => {
                    if (valid) {
                        this[action + 'Pop'] = false;
                        let data = this[action + 'Add'];
                        if (action !== 'maintain' && action !== 'maintenance') {
                            data.pid = this.id;
                        }
                        this.apiPost("Operation/house" + action + "Edit", data).then(res => {
                            let remind = res.error ? "error" : "success";
                            _g.toastMsg(remind, res.msg);
                            if (!res.error) {
                                this.getList(action);
                            } else {
                                this[action + 'Pop'] = true;
                            }
                        });
                    } else {
                        return false;
                    }
                });
            },

            /* 删除 */
            Del(id, action) {
                this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                    .then(() => {
                        let data = {id: id};
                        this.apiPost("Operation/house" + action + "Delete", data).then(res => {
                            if (!res.error) {
                                this.$message({
                                    type: "success",
                                    message: res.msg
                                });
                            } else {
                                this.$message({
                                    type: "error",
                                    message: res.msg
                                });
                            }
                            this.getList(action);
                        });
                    })
                    .catch(() => {
                        this.$message({
                            type: "info",
                            message: "已取消删除"
                        });
                    });
            },

            /* 打开新增窗口 */
            openAdd(action) {
                this[action + 'Add'] = _g.cloneJson(eval(action));
                if (action === 'maintenance') {
                    this.maintenanceAdd.asset_num = this.houseData.asset_num;
                    this.maintenanceAdd.asset_name = this.houseData.asset_name;
                } else if (action === 'maintain') {
                    this.maintainAdd.asset_num = this.houseData.asset_num;
                    this.maintainAdd.asset_name = this.houseData.asset_name;
                }
                this[action + 'Pop'] = true;
                this.$refs[action + 'RulesName'].resetFields();
            },

        },
    }
</script>

<style scoped>
    .headPic img {
        margin-left: 50px;
        width: 50%;
    }

    .add {
        width: 25px;
        height: 25px;
    }

    .stuInfo {
        margin-bottom: 20px;
    }
</style>